package actions;

//~--- non-JDK imports --------------------------------------------------------

import beans.Search;

import dto.Topics;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

//~--- JDK imports ------------------------------------------------------------

import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SearchAction extends org.apache.struts.action.Action {
    public SearchAction() {}

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                 HttpServletResponse response)
            throws Exception {
        ActionForward forward   = new ActionForward();
        String        searchreq = ((Search) form).getSearch();

        System.out.println("hhhhhhhhhhhhhhhhhhhhh" + searchreq);

        client.TopicsPosts tp     = new client.TopicsPosts();
        Vector<Topics>     topics = tp.search(searchreq);

        if (topics.size() != 0) {
            System.out.println("number of topics are" + topics.size());
            ((Search) form).setTopics(topics);

            // request.setAttribute("Search", (Search)form);
            forward = mapping.findForward("done");
            System.out.println("ddddooo");
        } else {
            forward = mapping.findForward("fail");
        }

        return forward;
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
